<?php

namespace app\index\controller;

use app\common\entity\Goods;
use app\common\entity\GoodsCategory;
use app\common\entity\Proportion;
use app\common\entity\TaskReward;
use app\common\entity\User;
use app\common\entity\Config;
use think\Request;
use think\Db;
use app\common\entity\Image;
use app\common\entity\Article;
use app\common\entity\Mark;
use app\common\entity\MarkConfig;
use app\common\entity\MywalletLog;
use app\common\entity\Task;
use app\common\entity\UserPackage;
use app\common\entity\PosLog;
use app\common\service\Users\Service;


class Index extends Base
{


    public function index(Request $request)
    {
        $img = Image::where('types', 1)->order('sort desc,id desc')->select();
        $notice = Article::where('category', 1)->where('status',1)->order('sort desc,article_id desc')->find();
        $category = GoodsCategory::order('sort asc')->select();
        $goods = Goods::where('status',1)->order('sort asc,addtime desc')->select();


        $info = ['banner'=>$img,'notice'=>$notice,'category'=>$category,'goods'=>$goods];
        return json(['code' => 0, 'message' => '请求成功', 'info' => $info]);
    }

    /**
     * 文章列表
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function article(Request $request){
        $category = $request->post('category',1);
        if(!$category){
            return json(['code' => 1, 'message' => '请求信息错误']);
        }
        $list = Article::where('category', $category)->where('status',1)->order('sort desc,article_id desc')->select();

        return json(['code' => 0, 'message' => '请求成功', 'info' => $list]);
    }

    /**
     * 文章详情
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function articleDetail(Request $request){
        $id = $request->param('id');
        if(!$id){
            return json(['code' => 1, 'message' => '请求信息错误']);
        }
        $info = Article::where('article_id', $id)->where('status',1)->find();


        $data = [
            'article_id'=>$info['article_id'],
            'category'=>$info['category'],
            'title'=>$info['title'],
            'content'=>$info['content'],
            'create_time'=>$info['create_time'],
            'status'=>$info['status'],
            'sort'=>$info['sort'],
            'start_time'=>$info['start_time'],
            'end_time'=>$info['end_time'],
            'pic'=>$info['pic'],
            'describe'=>$info['describe'],
        ];

        return json(['code' => 0, 'message' => '请求成功', 'info' => $data]);
    }


    #是否登录
    public function is_login()
    {

        if ($this->userId) {
            return json(['code' => 0, 'message' => 'yes', 'info' => $this->userId]);
        }
        return json(['code' => 10, 'message' => 'no', 'url' => 'login']);

    }












    public function tologin()
    {

        return json(['code' => 1, 'message' => '登录后可操作', 'url' => 'login']);

    }

}
